home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / GNU / oleo_src.lha / src / test.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-18  |  17.9 KB  |  945 lines

  1. /*    Copyright (C) 1990 Free Software Foundation, Inc.
  2.  
  3. This file is part of Oleo, the GNU Spreadsheet.
  4.  
  5. Oleo is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 1, or (at your option)
  8. any later version.
  9.  
  10. Oleo is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with Oleo; see the file COPYING.  If not, write to
  17. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. #include "funcdef.h"
  20. #ifdef TEST_YYLEX
  21.  
  22. #include <ctype.h>
  23.  
  24. /* #include "node.h"
  25. #include "eval.h"
  26. #include "var.h" */
  27.  
  28. CELLREF cur_row=1,cur_col=1;
  29.  
  30. struct node *yylval;
  31.  
  32. int
  33. main FUN0()
  34. {
  35.     char buf[80];
  36.     int ret;
  37.     extern char *instr;
  38.  
  39.     init_parse();
  40.     printf("Read lines and print what they lex to.\n");
  41.     while(printf("lex->"),gets(buf)) {
  42.         instr=buf;
  43.         while(ret=yylex()) {
  44.             if(isascii(ret))
  45.                 printf("'%c' ",ret);
  46.             else
  47.                 printf("%d ",ret);
  48.             if(yylval->comp_value) {
  49.                 putchar('[');
  50.                 /* printf("%d",yylval->node_type); */
  51.                 printf("%d",yylval->comp_value);
  52.                 switch(yylval->comp_value) {
  53.                 case CONST_FLT:
  54.                     printf(" %g",yylval->n_x.v_float);
  55.                     break;
  56.                 case CONST_INT:
  57.                     printf(" %ld",yylval->n_x.v_int);
  58.                     break;
  59.                 case CONST_STR:
  60.                     printf(" \"%s\"",yylval->n_x.v_string);
  61.                     break;
  62.                 case R_CELL:
  63.                     printf(" %d:%d",yylval->n_x.v_dex[0],yylval->n_x.v_dex[1]);
  64.                     break;
  65.                 case R_CELL|COLREL:
  66.                     printf(" %d:%+d",yylval->n_x.v_dex[0],yylval->n_x.v_dex[1]);
  67.                     break;
  68.                 case R_CELL|ROWREL:
  69.                     printf(" %+d:%d",yylval->n_x.v_dex[0],yylval->n_x.v_dex[1]);
  70.                     break;
  71.                 case R_CELL|ROWREL|COLREL:
  72.                     printf(" %+d:%+d",yylval->n_x.v_dex[0],yylval->n_x.v_dex[1]);
  73.                     break;
  74.  
  75.                 case SUM:
  76.                 case POW:
  77.                 case PROD:
  78.                 case MOD:
  79.                 case NOTEQUAL:
  80.                 case LESS:
  81.                 case LESSEQ:
  82.                 case GREATER:
  83.                 case GREATEQ:
  84.                 case EQUAL:
  85.                 case DIV:
  86.                 case DIFF:
  87.                     break;
  88.  
  89.                 case AREA_SUM:
  90.                 case AREA_PROD:
  91.                 case AREA_AVG:
  92.                 case AREA_STD:
  93.                 case AREA_MAX:
  94.                 case AREA_MIN:
  95.                     break;
  96.  
  97.                 default:
  98.                     printf(" ???");
  99.                     break;
  100.                 }
  101.                 putchar(']');
  102.                 putchar(' ');
  103.             }
  104.         }
  105.         putchar('\n');
  106.     }
  107.     return 0;
  108. }
  109.  
  110. struct var *
  111. find_or_make_var FUN2(char *, string, int, len)
  112. {
  113.     struct var *ret;
  114.     void *ck_malloc();
  115.  
  116.     ret=(struct var *)ck_malloc(sizeof(struct var)+len+1);
  117.     bcopy(string,ret->var_name,len);
  118.     ret->var_name[len]='\0';
  119.     ret->var_flags=VAR_UNDEF;
  120.     return ret;
  121. }
  122.  
  123. #endif
  124.  
  125. #ifdef TEST_PARSE
  126. /* #include "eval.h"
  127. #include "node.h"
  128. #include "var.h" */
  129.  
  130. CELLREF cur_row=1,cur_col=1;
  131.  
  132. void print_node EXT2(struct node *, int);
  133.  
  134. int
  135. main FUN0()
  136. {
  137.     char buf[200];
  138.     int ret;
  139.     extern char *instr;
  140.     extern struct node *parse_return;
  141.     extern int parse_error;
  142.  
  143.     init_parse();
  144.     printf("Read lines, parse them, and print the results\n");
  145.     while(printf("parse->"),gets(buf)) {
  146.         instr=buf;
  147.         ret=yyparse();
  148.         if(ret || parse_error)
  149.             printf("ERROR %d %d\n",ret,parse_error);
  150.         if(parse_return)
  151.             print_node(parse_return,0);
  152.         parse_free();
  153.     }
  154.     return 0;
  155. }
  156.  
  157. void
  158. print_node FUN2(struct node *,node, int,depth)
  159. {
  160.     struct function *f;
  161.  
  162.     f= &the_funs[node->comp_value];
  163.     printf("%*s %#x: comp %d  add %d comp %d\n",depth,"",node->comp_value,node->add_byte,f->fn_comptype);
  164.     switch(f->fn_comptype) {
  165.     case C_IF:
  166.         printf("Test-code:\n");
  167.         print_node(node->n_x.v_subs[0]->n_x.v_subs[0],depth+1);
  168.         printf("True-code:\n");
  169.         print_node(node->n_x.v_subs[0]->n_x.v_subs[1],depth+1);
  170.         printf("False-code:\n");
  171.         print_node(node->n_x.v_subs[1],depth+1);
  172.         break;
  173.  
  174.     case C_ANDOR:
  175.         printf("First-code:\n");
  176.         print_node(node->n_x.v_subs[0],depth+1);
  177.         printf("Second-code:\n");
  178.         print_node(node->n_x.v_subs[1],depth+1);
  179.         break;
  180.  
  181.     case C_ERR:
  182.         printf("Err %d",node->n_x.v_val);
  183.         break;
  184.  
  185.     case C_FLT:
  186.         printf("Float %.12g\n",node->n_x.v_float);
  187.         break;
  188.  
  189.     case C_INT:
  190.         printf("Int %ld\n",node->n_x.v_int);
  191.         break;
  192.  
  193.     case C_STR:
  194.         printf("String \"%s\"\n",node->n_x.v_string);
  195.         break;
  196.  
  197.     case C_VAR:
  198.         printf("Var %#x\n",node->n_x.v_var);
  199.         break;
  200.  
  201.     case C_CELL:
  202.         printf("Cell %d %d\n",node->n_x.v_dex[0],node->n_x.v_dex[1]);
  203.         break;
  204.  
  205.     case C_RANGE:
  206.         printf("Range %d %d %d %d\n",node->n_x.v_dex[0],node->n_x.v_dex[1],node->n_x.v_dex[2],node->n_x.v_dex[3]);
  207.         break;
  208.  
  209.     case C_FN0:
  210.     case C_TIM|C_FN0:
  211.         printf("FUN0: %s\n",f->fn_str);
  212.         break;
  213.  
  214.     case C_FN1:
  215.     case C_TIM|C_FN1:
  216.     case C_FN0X:
  217.         printf("FUN1: %s\n",f->fn_str);
  218.         print_node(node->n_x.v_subs[0],depth+1);
  219.         break;
  220.  
  221.     case C_FN2:
  222.     case C_TIM|C_FN2:
  223.         printf("FUN2: %s  First:\n",f->fn_str);
  224.         print_node(node->n_x.v_subs[0],depth+1);
  225.         printf("Second:\n");
  226.         print_node(node->n_x.v_subs[1],depth+1);
  227.         break;
  228.  
  229.     case C_FN3:
  230.     case C_TIM|C_FN3:
  231.         printf("FUN3: %s  First:\n",f->fn_str);
  232.         print_node(node->n_x.v_subs[0]->n_x.v_subs[0],depth+1);
  233.         printf("Second:\n");
  234.         print_node(node->n_x.v_subs[0]->n_x.v_subs[1],depth+1);
  235.         printf("Third:\n");
  236.         print_node(node->n_x.v_subs[1],depth+1);
  237.         break;
  238.  
  239.     case C_FN4:
  240.     case C_TIM|C_FN4:
  241.         printf("FUN4: %s  First:\n",f->fn_str);
  242.         print_node(node->n_x.v_subs[0]->n_x.v_subs[0],depth+1);
  243.         printf("Second:\n");
  244.         print_node(node->n_x.v_subs[0]->n_x.v_subs[1],depth+1);
  245.         printf("Third:\n");
  246.         print_node(node->n_x.v_subs[1]->n_x.v_subs[0],depth+1);
  247.         printf("Fourth:\n");
  248.         print_node(node->n_x.v_subs[1]->n_x.v_subs[1],depth+1);
  249.         break;
  250.  
  251.     case C_FNN:
  252.         printf("FNN: %s  First:\n",f->fn_str);
  253.         for(node=node->n_x.v_subs[0];node;node=node->n_x.v_subs[1])
  254.             print_node(node->n_x.v_subs[0],depth+1);
  255.         break;
  256.  
  257.     default:
  258.         panic("Unknown fn_comptype %d",f->fn_comptype);
  259.     }
  260. }
  261.  
  262. struct var *
  263. find_or_make_var FUN2(char *, string, int, len)
  264. {
  265.     struct var *ret;
  266.     void *ck_malloc();
  267.  
  268.     ret=(struct var *)ck_malloc(sizeof(struct var)+len+1);
  269.     bcopy(string,ret->var_name,len);
  270.     ret->var_name[len]='\0';
  271.     ret->var_flags=VAR_UNDEF;
  272.     return ret;
  273. }
  274.  
  275. #endif
  276.  
  277. #ifdef TEST_COMPILE
  278. /* #include "var.h" */
  279.  
  280. unsigned char cur_row=1, cur_col=1;
  281.  
  282. int
  283. main FUN0()
  284. {
  285.     char buf[200];
  286.     unsigned char *ret;
  287.     extern char *instr;
  288.     extern unsigned char *byte_compile();
  289.  
  290.     init_parse();
  291.     init_byte();
  292.     printf("Read lines, parse and compile them, and print the results\n");
  293.     while(printf("compile->"),gets(buf)) {
  294.         instr=buf;
  295.         yyparse();
  296.         ret=byte_compile();
  297.         print_decompile(ret);
  298.     }
  299.     return 0;
  300. }
  301.  
  302. struct var *
  303. find_or_make_var FUN2(char *, string, int, len)
  304. {
  305.     struct var *ret;
  306.     void *ck_malloc();
  307.  
  308.     ret=(struct var *)ck_malloc(sizeof(struct var)+len+1);
  309.     bcopy(string,ret->var_name,len);
  310.     ret->var_name[len]='\0';
  311.     ret->var_flags=VAR_UNDEF;
  312.     return ret;
  313. }
  314.  
  315. void
  316. add_timer_ref FUN2(unsigned char,type, int,whereto)
  317. {
  318.     printf("Add timer ref %d to %d\n",type, whereto);
  319. }
  320.  
  321. void
  322. add_ref FUN3(unsigned char, type, short, rowbit, short, colbit)
  323. {
  324.     printf("ref %d to %d, %d\n",type, rowbit,colbit);
  325. }
  326.  
  327. void
  328. add_range_ref FUN5(unsigned char, type,
  329.             short, r1bit,
  330.              short, c1bit,
  331.              short, r2bit,
  332.              short, c2bit)
  333. {
  334.     printf("r_ref %d to %d:%d, %d:%d\n",type,r1bit,r2bit,c1bit,c2bit);
  335. }
  336.  
  337. void
  338. add_var_ref FUN1(struct var *, var)
  339. {
  340.     printf("v_ref\n");
  341. }
  342.  
  343. #endif
  344.  
  345. #ifdef TEST_DECOMPILE
  346. /* #include "var.h" */
  347.  
  348. struct pr_node {
  349.     int tightness;
  350.     int len;
  351.     char string[1];
  352. };
  353.  
  354. char inbuf[120];
  355.  
  356. CELLREF cur_row = 1, cur_col = 1;
  357.  
  358. struct pr_node *byte_decompile();
  359.  
  360. main FUN0()
  361. {
  362.     unsigned char *prog;
  363.     struct pr_node *ptr;
  364.     unsigned char *parse_and_compile();
  365.  
  366.     printf("Read a line, parse, byte-compile, decompile it\n");
  367.     init_parse();
  368.     while(printf("decomp->"),gets(inbuf)) {
  369.         prog=parse_and_compile(inbuf);
  370.         if(!prog) {
  371.             printf("couldn't parse\n");
  372.             continue;
  373.         }
  374.         ptr=byte_decompile(prog);
  375.         printf("'%d: %s'\n", ptr->len, ptr->string);
  376.     }
  377. }
  378.  
  379. struct var *
  380. find_or_make_var FUN2(char *, string, int, len)
  381. {
  382.     struct var *ret;
  383.     void *ck_malloc();
  384.  
  385.     ret=(struct var *)ck_malloc(sizeof(struct var)+len+1);
  386.     bcopy(string,ret->var_name,len);
  387.     ret->var_name[len]='\0';
  388.     ret->var_flags=VAR_UNDEF;
  389.     return ret;
  390. }
  391.  
  392. void
  393. add_timer_ref FUN2(unsigned char,type, int,whereto)
  394. {
  395.     printf("Add timer ref %d to %d\n",type, whereto);
  396. }
  397.  
  398. void
  399. add_ref FUN3(unsigned char, type, short, rowbit, short, colbit)
  400. {
  401.     printf("ref %d to %d, %d\n",type, rowbit,colbit);
  402. }
  403.  
  404. void
  405. add_range_ref FUN5(unsigned char, type,
  406.             short, r1bit,
  407.              short, c1bit,
  408.              short, r2bit,
  409.              short, c2bit)
  410. {
  411.     printf("r_ref %d to %d:%d, %d:%d\n",type,r1bit,r2bit,c1bit,c2bit);
  412. }
  413.  
  414. void
  415. add_var_ref FUN1(struct var *, var)
  416. {
  417.     printf("v_ref\n");
  418. }
  419.  
  420. #endif
  421.  
  422. #ifdef TEST_EVAL
  423. /* #include "cell.h"
  424. #include "var.h" */
  425.  
  426. struct value {
  427.     int    type;
  428.     union vals x;
  429. };
  430. #define Float    x.c_d
  431. #define String    x.c_s
  432. #define Int    x.c_l
  433. #define Value    x.c_i
  434. #define Index    x.c_x
  435.  
  436. struct cell v[10][10];
  437.  
  438. void
  439. push_refs()
  440. {
  441. }
  442.  
  443. void
  444. set_cell FUN3(CELLREF, row, CELLREF, col,struct value *, val)
  445. {
  446.     v[row][col].cell_flags= val->type;
  447.     v[row][col].c_z=val->x;
  448. }
  449.  
  450. struct cell *
  451. find_cell FUN2(CELLREF, row,CELLREF, col)
  452. {
  453.     return &v[row][col];
  454. }
  455.  
  456. struct cell *
  457. find_or_make_cell FUN2(CELLREF, row, CELLREF, col)
  458. {
  459.     return &v[row][col];
  460. }
  461.  
  462. struct var *
  463. find_or_make_var FUN2(char *, string, int, len)
  464. {
  465.     struct var *ret;
  466.     void *ck_malloc();
  467.  
  468.     ret=(struct var *)ck_malloc(sizeof(struct var)+len+1);
  469.     bcopy(string,ret->var_name,len);
  470.     ret->var_name[len]='\0';
  471.     ret->var_flags=VAR_UNDEF;
  472.     return ret;
  473. }
  474.  
  475. void
  476. add_ref FUN3(unsigned char, type, short, rowbit, short, colbit)
  477. {
  478.     printf("ref %d to %d, %d\n",type, rowbit,colbit);
  479. }
  480.  
  481. void
  482. add_range_ref FUN5(unsigned char, type,
  483.             short, r1bit,
  484.              short, c1bit,
  485.              short, r2bit,
  486.              short, c2bit)
  487. {
  488.     printf("r_ref %d to %d:%d, %d:%d\n",type,r1bit,r2bit,c1bit,c2bit);
  489. }
  490.  
  491. void
  492. add_var_ref FUN1(struct var *, var)
  493. {
  494.     printf("v_ref\n");
  495. }
  496.  
  497. int
  498. main FUN0()
  499. {
  500.     char inbuf[160];
  501.     char *ptr;
  502.     unsigned char *prog;
  503.     struct value *ret;
  504.     int row,col;
  505.  
  506.     extern unsigned char *parse_and_compile();
  507.     struct value *eval_expression();
  508.  
  509.     init_eval();
  510.     init_parse();
  511.  
  512.     for(row=0;row<10;row++)
  513.         for(col=0;col<10;col++) {
  514.             v[row][col].cell_int=row*col+row+col;
  515.             v[row][col].cell_flags=TYP_INT;
  516.         }
  517.  
  518.     printf("read in a line, parse, compile, and eval it\n");
  519.     while(printf("eval->"),gets(inbuf)) {
  520.         ptr=inbuf;
  521.         if(inbuf[0]==' ') {
  522.             ptr++;
  523.             row=astol(&ptr);
  524.             if(*ptr==',')
  525.                 ptr++;
  526.             col=astol(&ptr);
  527.         } else row= -1;
  528.         prog=parse_and_compile(ptr);
  529.         if(!prog) {
  530.             printf("Compile failed\n");
  531.             continue;
  532.         }
  533.         ret=eval_expression(prog);
  534.         switch(ret->type) {
  535.         case TYP_FLT:
  536.             printf("(float) %g\n",ret->Float);
  537.             break;
  538.         case TYP_INT:
  539.             printf("(int) %ld\n",ret->Int);
  540.             break;
  541.         case TYP_ERR:
  542.             printf("(error) %d\n",ret->Value);
  543.             break;
  544.         case TYP_BOL:
  545.             printf("(bool) %s\n",ret->Value? "TRUE" : "FALSE");
  546.             break;
  547.         case TYP_STR:
  548.             printf("(string) '%s'\n",ret->String);
  549.             break;
  550.         default:
  551.             printf("Eh, wot\n");
  552.             break;
  553.         }
  554.         if(row!=-1)
  555.             set_cell(row,col,ret);
  556.     }
  557.     return 0;
  558. }
  559.  
  560. #endif
  561.  
  562. #ifdef TEST_CELL
  563. /* #include "cell.h" */
  564.  
  565. struct init {
  566.     CELLREF row,col;
  567. };
  568.  
  569. struct init inits [] = {
  570.     { 0, 3},{ 0, 2},{ 0, 1},{ 0, 5},{ 0, 4}, { 0,10},{ 0,11},{ 0,12},
  571.  
  572.  
  573.     { 3, 1},
  574.  
  575.  
  576.  
  577.  
  578.     { 8, 4},{ 8, 3},{ 8, 2},{ 8, 5},{ 8, 6},
  579.     { 9, 0},{ 9, 1},{ 9, 2},{ 9, 6},{ 9, 7},
  580.  
  581.  
  582.     {12, 1},{12, 2},{12, 3},{12, 4},{12, 5}, {12, 6},{12, 7},{12, 8},{12, 9},
  583.  
  584.     {20, 0},{20, 8},{20, 7},{20, 6},{20, 9}, {20,10},{20,11},{20,12},{20,13},
  585.     {21, 0},{21, 8},{21, 7},{21, 6},{21, 5}, {21, 9},{21,10},{21,11},{21,12},{21,13},{21,14},{21,14},{21,15},{21,16},
  586.     {22, 0},{22, 7},{22, 6},{22, 5},{22, 8}, {22, 9},
  587.     {23, 0},{23,14},{23,13},{23,12},{23,15}, {23,16},
  588.     {24, 0},{24, 7},{24, 6},{24, 5},{24, 8}, {24, 9}, {24,14},{24,13},{24,12},{24,15},{24,16},
  589.     {25, 0},
  590.     {26, 0},
  591.     {27, 0},
  592.     {28, 0},
  593.     {29, 0},
  594.     {30, 0},
  595.     {31, 0},
  596.  
  597. };
  598.  
  599. main FUN0()
  600. {
  601.     char inbuf[160];
  602.     char *ptr;
  603.     char fun;
  604.     long row,row1,col,col1;
  605.     long num;
  606.     struct cell *ret;
  607.     struct init *ip;
  608.  
  609.     for(ip=inits;ip<&inits[sizeof(inits)/sizeof(inits[0])];ip++) {
  610.         ret=find_or_make_cell(ip->row,ip->col);
  611.         ret->cell_flags=1;
  612.         ret->cell_int=10000L+ip->row*100+ip->col;
  613.     }
  614.  
  615.     while(printf("cell-> "),gets(inbuf)) {
  616.         ptr=inbuf;
  617.         switch(*ptr) {
  618.         case 'f':
  619.             ptr++;
  620.             row=astol(&ptr);
  621.             col=astol(&ptr);
  622.             ret=find_cell((CELLREF)row,(CELLREF)col);
  623.             if(!ret)
  624.                 printf("(null)\n");
  625.             else if(!ret->cell_flags)
  626.                 printf("'%ld'\n",ret->cell_int);
  627.             else
  628.                 printf("%ld\n",ret->cell_int);
  629.             break;
  630.  
  631.         case 'm':
  632.             ptr++;
  633.             row=astol(&ptr);
  634.             col=astol(&ptr);
  635.             ret=find_or_make_cell((CELLREF)row,(CELLREF)col);
  636.             ret->cell_flags=1;
  637.             ret->cell_int=astol(&ptr);
  638.             break;
  639.  
  640.         case ' ':
  641.             ptr++;
  642.             row=astol(&ptr);
  643.             row1=astol(&ptr);
  644.             col=astol(&ptr);
  645.             col1=astol(&ptr);
  646.             find_cells_in_range((CELLREF)row, (CELLREF)col, (CELLREF)row1, (CELLREF)col1);
  647.             while(ret=next_cell_in_range()) {
  648.                 if(!ret->cell_flags)
  649.                     printf("'%ld'\n",ret->cell_int);
  650.                 else
  651.                     printf("%ld\n",ret->cell_int);
  652.             }
  653.             break;
  654.  
  655.         case 'i':
  656.             fun= *++ptr;
  657.             ptr++;
  658.             row=astol(&ptr);
  659.             num=astol(&ptr);
  660.             col=astol(&ptr);
  661.             col1=astol(&ptr);
  662.             if(fun=='r')
  663.                 insert_rows((CELLREF)row,num,(CELLREF)col,(CELLREF)col1);
  664.             else if(fun=='c')
  665.                 insert_cols((CELLREF)row,num,(CELLREF)col,(CELLREF)col1);
  666.             else
  667.                 printf("'ir' or 'ic' only\n");
  668.             break;
  669.  
  670.         case 'd':
  671.             fun= *++ptr;
  672.             ptr++;
  673.             row=astol(&ptr);
  674.             num=astol(&ptr);
  675.             col=astol(&ptr);
  676.             col1=astol(&ptr);
  677.             if(fun=='r')
  678.                 delete_rows((CELLREF)row,num,(CELLREF)col,(CELLREF)col1);
  679.             else if(fun=='c')
  680.                 delete_cols((CELLREF)row,num,(CELLREF)col,(CELLREF)col1);
  681.             else
  682.                 printf("'dr' or 'dc' only\n");
  683.             break;
  684.  
  685.         case 'p':
  686.             ptr++;
  687.             col=astol(&ptr);
  688.             col1=astol(&ptr);
  689.             row=astol(&ptr);
  690.             row1=astol(&ptr);
  691.             while(row<=row1) {
  692.                 for(num=col;num<=col1;num++) {
  693.                     ret=find_cell((CELLREF)row,(CELLREF)num);
  694.                     if(!ret)
  695.                         printf("     . ");
  696.                     else if(!ret->cell_flags)
  697.                         printf("'%5ld ",ret->cell_int);
  698.                     else
  699.                         printf("%6ld ",ret->cell_int);
  700.                 }
  701.                 putchar('\n');
  702.                 row++;
  703.             }
  704.             break;
  705.  
  706.         case 'P':
  707.             print_array(0);
  708.             break;
  709.  
  710.         default:
  711.             printf("'f', 'm', 'i', 'd', or ' ' only\n");
  712.             break;
  713.         }
  714.     }
  715. }
  716. #endif
  717.  
  718. #ifdef TEST_REF
  719. #include <stdio.h>
  720. /* #include "cell.h"
  721. #include "var.h" */
  722.  
  723. main FUN0()
  724. {
  725.     char inbuf[160];
  726.     CELLREF row,col;
  727.     CELLREF lr,hr,lc,hc;
  728.     CELL *cp;
  729.     char *ptr;
  730.     FILE *fp;
  731.     char base,fun;
  732.     int num;
  733.     extern unsigned short current_cycle;
  734.  
  735.     init_parse();
  736.     init_eval();
  737.     init_refs();
  738.     fp=stdin;
  739.     current_cycle++;
  740.     printf("Read lines of row,col_expr and eval/store\n");
  741.     for(;;) {
  742.         printf("ref-> ");
  743.         if(!fgets(inbuf,160,fp)) {
  744.             if(fp==stdin)
  745.                 break;
  746.             printf("<EOF>\n");
  747.             fclose(fp);
  748.             fp=stdin;
  749.             continue;
  750.         } else if(fp!=stdin)
  751.             printf(inbuf);
  752.         ptr=inbuf;
  753.         while(*ptr && *ptr!='\n')
  754.             ptr++;
  755.         if(*ptr=='\n')
  756.             *ptr=0;
  757.         ptr=inbuf;
  758.         switch(*ptr) {
  759.         case 'f':
  760.             ptr++;
  761.             while(*ptr==' ')
  762.                 ptr++;
  763.             fp=fopen(ptr,"r");
  764.             if(!fp) {
  765.                 fp=stdin;
  766.                 perror(ptr);
  767.             }
  768.             break;
  769.         case 'p':
  770.             ptr++;
  771.             lr=astol(&ptr)-1;
  772.             if(*ptr==',')
  773.                 ptr++;
  774.             hr=astol(&ptr)-1;
  775.             if(*ptr==',')
  776.                 ptr++;
  777.             lc=astol(&ptr)-1;
  778.             if(*ptr==',')
  779.                 ptr++;
  780.             hc=astol(&ptr)-1;
  781.             if(*ptr==',')
  782.                 ptr++;
  783.  
  784.             if(lr<MIN_ROW || lr>MAX_ROW || hr<MIN_ROW || hr>MAX_ROW
  785.                 || lc<MIN_COL || lc>MAX_COL || hc<MIN_COL || hc>MAX_COL) {
  786.                 printf("Out of range?\n");
  787.                 break;
  788.             }
  789.             for(row=lr;row<=hr;row++) {
  790.                 int space = 0;
  791.  
  792.                 for(col=lc;col<=hc;col++) {
  793.                     cp=find_cell(row,col);
  794.                     if(!cp)
  795.                         space+=11;
  796.                     else {
  797.                         if(space) {
  798.                             printf("%*s",space,"");
  799.                             space=0;
  800.                         }
  801.                         pr_cell(MAX_ROW,MAX_COL,cp);
  802.                     }
  803.                 }
  804.                 printf("\n");
  805.                 space=0;
  806.             }
  807.             break;
  808.  
  809.         case 's':
  810.             ptr++;
  811.             row=astol(&ptr)-1;
  812.             if(*ptr==',')
  813.                 ptr++;
  814.             col=astol(&ptr)-1;
  815.             if(row<MIN_ROW || row>MAX_ROW || col<MIN_COL || col>MAX_COL) {
  816.                 printf("Out of range?\n");
  817.                 break;
  818.             }
  819.             cp=find_cell(row,col);
  820.             if(!cp)
  821.                 printf("No Can Do!\n");
  822.             else {
  823.                 printf("%d,%d",row,col);
  824.                 pr_cell(row,col,cp);
  825.                 printf("\n");
  826.             }
  827.             break;
  828.  
  829.         case 'P':
  830.             print_array(0);
  831.             break;
  832.  
  833.         case 'd':
  834.         case 'i':
  835.             base= *ptr++;
  836.             fun = *ptr++;
  837.             row=astol(&ptr)-1;
  838.             if(*ptr==',')
  839.                 ptr++;
  840.             num=astol(&ptr);
  841.             if(*ptr==',')
  842.                 ptr++;
  843.             lc=astol(&ptr)-1;
  844.             if(*ptr==',')
  845.                 ptr++;
  846.             hc=astol(&ptr)-1;
  847.             if(*ptr==',')
  848.                 ptr++;
  849.             if(base=='i') {
  850.                 if(fun=='r') {
  851.                     shift_ref(row, MAX_ROW, lc, hc, num, 0);
  852.                     insert_rows(row,num,lc,hc);
  853.                 } else if(fun=='c') {
  854.                     shift_ref(lc, hc, row, MAX_COL, 0, num);
  855.                     insert_cols(row,num,lc,hc);
  856.                 } else
  857.                     base='?';
  858.             }
  859.             if(base=='d') {
  860.                 if(fun=='r') {
  861.                     shift_ref(row, MAX_ROW, lc, hc, -num, 0);
  862.                     delete_rows(row,num,lc,hc);
  863.                 } else if(fun=='c') {
  864.                     shift_ref(lc, hc, row, MAX_COL, 0, -num);
  865.                     delete_cols(row,num,lc,hc);
  866.                 } else
  867.                     base='?';
  868.             }
  869.             if(base!='i' && base!='d')
  870.                 printf("[ir   ic   dr   dc]    <startat> <number> <low> <high>\n");
  871.             break;
  872.         case 'v':
  873.             ptr++;
  874.             while(*ptr==' ')
  875.                 ptr++;
  876.             for(num=0;ptr[num] && ptr[num]!=' ';num++)
  877.                 ;
  878.             if(ptr[num]) {
  879.                 ptr=new_var_value(ptr,num,&ptr[num+1]);
  880.                 if(ptr)
  881.                     printf("Fail: %s\n",ptr);
  882.             }
  883.             break;
  884.  
  885.         default:
  886.             printf("f <filename>   [id][rc] <numbers>   p   P   or <row> <col> <formula>\n");
  887.             break;
  888.  
  889.         case ' ':
  890.         case '0': case '1': case '2': case '3': case '4':
  891.         case '5': case '6': case '7': case '8': case '9':
  892.             row=astol(&ptr)-1;
  893.             if(*ptr==',')
  894.                 ptr++;
  895.             col=astol(&ptr)-1;
  896.             if(row<MIN_ROW || row>MAX_ROW || col<MIN_COL || col>MAX_COL) {
  897.                 printf("Out of range?\n");
  898.                 break;
  899.             }
  900.             ptr=new_value(row, col, ptr);
  901.             if(ptr)
  902.                 printf("Fail: %s\n",ptr);
  903.             else
  904.                 pr_cell(row,col,find_cell(row,col));
  905.             break;
  906.         }
  907.         current_cycle++;
  908.         while(eval_next_cell())
  909.             ;
  910.     }
  911. }
  912. void
  913. pr_cell FUN3(CELLREF, r,  CELLREF, c,  CELL *,cell)
  914. {
  915.     if(r!=MAX_ROW)
  916.         printf("%d,%d: ",r+1, c+1);
  917.     switch(GET_TYP(cell)) {
  918.     case 0:
  919.         printf("     .     ");
  920.         break;
  921.     case TYP_FLT:
  922.         printf("f%010g",cell->cell_flt);
  923.         break;
  924.     case TYP_INT:
  925.         printf("i%010ld",cell->cell_int);
  926.         break;
  927.     case TYP_ERR:
  928.         printf("e%010d",cell->cell_err);
  929.         break;
  930.     case TYP_BOL:
  931.         printf("b%10s",cell->cell_bol ? "TRUE" : "FALSE");
  932.         break;
  933.     case TYP_STR:
  934.         printf("s%10s",cell->cell_str);
  935.         break;
  936.     default:
  937.         printf("Eh, wot    ");
  938.         break;
  939.     }
  940.     if(r!=MAX_ROW)
  941.         printf("\n");
  942. }
  943.  
  944. #endif
  945.